﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SmsLib;

namespace SmsLib.UnitTests
{
    [TestClass]
    public class ShortMessageTests
    {
        private ShortMessage sm = null;
        private int port = 10;
        private uint baudRate = 57600;
        [TestMethod]
        public void StartService_ShouldConnectTheDevice()
        {
            CreateSM(port, baudRate);
            var result = sm.Start();
            Assert.IsTrue(result);
        }
        [TestMethod]
        public void StartService_WrongPort_ShuoldNotConnectTheDevice()
        {
            port = 9;
            CreateSM(port, baudRate);
            var result = sm.Start();
            Assert.IsFalse(result);
        }
        [TestMethod]
        public void StartService_WrongRate_ShouldNotConnectTheDevice()
        {
            baudRate = 115200;
            CreateSM(port, baudRate);
            var result = sm.Start();
            Assert.IsFalse(result);
        }

        private void CreateSM(int port, uint rate)
        {
            sm = new ShortMessage(port, rate);
        }

        [TestMethod]
        public void Send_RightNumber_ShouldReceiveTheMessage()
        {
            CreateSM(port, baudRate);
            sm.Start();
            var result = sm.Send("18702324320", "测试信息");
            Assert.IsTrue(result);
        }

        [TestCleanup]
        public void TearDown()
        {
            sm.Dispose();
        }
    }
}
